package com.yht.weblog.web.convert;

import com.yht.weblog.common.domain.dos.ArticleDO;
import com.yht.weblog.web.model.vo.archive.FindArchiveArticleRspVO;
import com.yht.weblog.web.model.vo.article.FindIndexArticlePageListRspVO;
import com.yht.weblog.web.model.vo.category.FindCategoryArticlePageListRspVO;
import com.yht.weblog.web.model.vo.tag.FindTagArticlePageListRspVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @author: yht
 * @date: 2024/1/9 23:20
 * @description:
 **/
@Mapper
public interface ArticleConvert {
    /**
     * 初始化 convert 实例
     */
    ArticleConvert INSTANCE = Mappers.getMapper(ArticleConvert.class);

    /**
     * 文章DO转换成首页文章分页列表VO
     * @param articleDO
     * @return
     */
    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    FindIndexArticlePageListRspVO convertDO2VO(ArticleDO articleDO);

    /**
     * 文章DO转换成归档文章VO
     * @param articleDO
     * @return
     */
    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    @Mapping(target = "createMonth", expression = "java(java.time.YearMonth.from(articleDO.getCreateTime()))")
    FindArchiveArticleRspVO convertDO2ArchiveArticleVO(ArticleDO articleDO);

    /**
     * 文章DO转换成分类文章分页列表VO
     * @param articleDO
     * @return
     */
    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    FindCategoryArticlePageListRspVO convertDO2CategoryArticleVO(ArticleDO articleDO);

    /**
     * 文章DO转换成标签文章分页列表VO
     * @param articleDO
     * @return
     */
    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    FindTagArticlePageListRspVO convertDO2TagArticleVO(ArticleDO articleDO);
}
